package com.shujia.flink.tf;

import org.apache.flink.api.common.functions.FilterFunction;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

public class Demo03Filter {
    public static void main(String[] args) throws Exception {
        // 过滤数据，注意返回值必须是布尔类型，返回true则保留数据，返回false则过滤数据
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        DataStream<String> ds = env.socketTextStream("master", 8888);

        // 只输出大于10的数字
        SingleOutputStreamOperator<String> filterDS = ds.filter(new FilterFunction<String>() {
            @Override
            public boolean filter(String value) throws Exception {
                return Integer.parseInt(value) > 10;
            }
        });
        filterDS.print();

        ds.filter(value -> Integer.parseInt(value) > 10).print();


        env.execute();

    }
}
